#导包
import pandas as pd
from xgboost import XGBRegressor
import datetime
#读取数据
data = pd.read_csv('data/train.csv')
#了解数据
print(data.head())
data.info()
#将时间戳转换成日期格式
data['time'] = pd.to_datetime(data['time']).dt.strftime('%Y-%m-%d %H:%M:%S')
data['hour'] = data['time'].str[11:13]
data['month'] = data['time'].str[5:7]
#对月份和小时进行热编码
data = pd.get_dummies(data,columns=['month','hour'])
# 对小时进行one-hot编码
hour_encoding = pd.get_dummies(data['hour'])
hour_encoding.columns = ['hour_' + str(i) for i in hour_encoding.columns]
# 对月份进行one-hot编码
month_encoding = pd.get_dummies(data['month'])
month_encoding.columns = ['month_' + str(i) for i in month_encoding.columns]
# 对one-hot编码后的结果进行拼接
result = pd.concat([data, hour_encoding, month_encoding], axis=1)
print(data.head())
print(data.columns)


